package com.jjyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jjyu.dao.UserFavoriteRestaurantMapper;
import com.jjyu.entity.UserFavoriteRestaurant;
import com.jjyu.service.UserFavoriteRestaurantService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户餐厅收藏服务实现类
 */
@Service
public class UserFavoriteRestaurantServiceImpl extends ServiceImpl<UserFavoriteRestaurantMapper, UserFavoriteRestaurant> implements UserFavoriteRestaurantService {
    @Override
    public List<UserFavoriteRestaurant> getFavoritesByUserId(Integer userId) {
        QueryWrapper<UserFavoriteRestaurant> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return list(queryWrapper);
    }
    @Override
    public boolean existsByUserIdAndRestaurantId(Integer userId, Integer restaurantId) {
        QueryWrapper<UserFavoriteRestaurant> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId)
                .eq("restaurant_id", restaurantId);
        return count(queryWrapper) > 0; // 如果数量大于0，表示已收藏
    }

}
